// pages/biaodan/biaodan.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    red: '../../images/red.png',
    green: '../../images/green.png',
    yellow: '../../images/yellow.png', //20.89
    sg: 0, //cm
    tz: 0, //g
    mbtz: 0, //kg
    // gmy:'无', 
    // tsjb:'无', 
    // mxjb:'无', 
    btnIndex: 0,
    list: [{
        title: '修身型',
        color: '#3D83E5',
        active: true,
      },
      {
        title: '特殊性',
        color: '#57BF6A',
        active: false,
      },
      {
        title: '养生型',
        color: '#ECA150',
        active: false,
      },

    ],
    btnList: ['经期', '备孕', '怀孕', '哺乳'],
    ysList: [{
      title: '过敏原',
      value: ""
    }, {
      title: '特殊疾病',
      value: ""
    }, {
      title: '慢性疾病',
      value: ""
    }],
  },
  tapCheckbox: function (e) {
    // console.log(e.currentTarget.dataset.i);
    var i = e.currentTarget.dataset.i
    var d = this.data.list
    d[i].active = !d[i].active
    this.setData({
      list: d
    })
    var cnt = 0
    for (var ii = 0; ii < d.length; ii++) {
      if (d[ii].active) {
        cnt++
      }
    }
    console.log(cnt);
    if (cnt == 0) {
      wx.showModal({
        title: '请至少选择一种类型',
      })
      d[i].active = true
      this.setData({
        list: d
      })
    }



  },
  go:function(e){
    wx.switchTab({
      url: '../index/index',
    })
  },
  getBmi() {
    var bmi = (this.data.tz / (this.data.sg * this.data.sg)).toFixed(2)
    console.log(bmi);
  },
  changeBtn(e) {
    this.setData({
      btnIndex: e.currentTarget.dataset.index
    })
    wx.setStorageSync('btnIndex', e.currentTarget.dataset.index)
  },
  clickMe(e) {
    wx.showToast({
      title: '已提交',
      icon: 'success'
    })
  },
  alertMsg: function (e) {
    var index = e.currentTarget.dataset.index
    console.log(index);
    if (index == 0) {
      wx.navigateTo({
        url: '../alertOne/alertOne',
      })
    } else if (index == 2) {
      wx.navigateTo({
        url: '../alertThree/alertThree',
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    this.setData({
      sg: options.height,
      tz: options.weight,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var info = wx.getStorageSync('userInfoF')
    console.log(info.sg);
    // this.setData({
    // })

    var ysList = wx.getStorageSync('ysList')
    if (ysList.length == 3) {
      this.setData({
        ysList,
      })
    }
    this.setData({
      btnIndex: wx.getStorageSync('btnIndex'),
      sg: info.sg,
      tz: info.tz,
      mbtz: info.mbtz
    })
    console.log(this.data.sg);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
// localStorage.setItem("list",)
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})